import 'dart:async';

import 'package:flutter/foundation.dart';

class DataBloc<T> {
  final StreamController<T> _controller = StreamController();

  final ValueSetter<T> callback;
  StreamSubscription _subscription;

  DataBloc(this.callback) {
    _subscription = _controller.stream.listen(callback);
  }

  add(T event) {
    _controller.add(event);
  }

  close() {
    _subscription.cancel();
    _controller.close();
  }
}
